package com.zx.notification.common.event;

import com.zx.notification.common.model.NotificationPushTasks;
import lombok.Getter;
import lombok.Setter;
import org.springframework.context.ApplicationEvent;

/**
 * 通知推送事件
 * 包含推送任务的详细信息
 */
@Getter
@Setter
public class NotificationPushEvent extends ApplicationEvent {

    /**
     * 通知ID
     */
    private String notificationId;

    /**
     * 渠道类型
     */
    private String channelType;

    /**
     * 消息队列类型
     */
    private String mqType;

    /**
     * 消费模式: QUEUE-点对点,TOPIC-广播
     */
    private String consumeMode;

    /**
     * 目标名称: 根据消费模式选择对应的目标名称(QUEUE模式取queue_name，TOPIC模式取topic_name)
     */
    private String destinationName;

    /**
     * 目标类型: 根据消费模式选择对应的目标类型(QUEUE模式取queue_destination_type，TOPIC模式取topic_destination_type)
     */
    private String destinationType;

    /**
     * 路由键(RabbitMQ专用)
     */
    private String routingKey;

    /**
     * 标签(RocketMQ专用)
     */
    private String tag;

    /**
     * 推送策略
     */
    private String pushStrategy;

    /**
     * 任务ID
     */
    private String taskId;

    public NotificationPushEvent(Object source) {
        super(source);
    }

    public NotificationPushEvent(Object source, String notificationId, String channelType, String mqType,
                                 String consumeMode, String destinationName, String destinationType,
                                 String routingKey, String tag, String pushStrategy) {
        super(source);
        this.notificationId = notificationId;
        this.channelType = channelType;
        this.mqType = mqType;
        this.consumeMode = consumeMode;
        this.destinationName = destinationName;
        this.destinationType = destinationType;
        this.routingKey = routingKey;
        this.tag = tag;
        this.pushStrategy = pushStrategy;
    }

    public NotificationPushEvent(Object source, String notificationId, String channelType, String mqType,
                                 String consumeMode, String destinationName, String destinationType,
                                 String routingKey, String tag, String pushStrategy, String taskId) {
        super(source);
        this.notificationId = notificationId;
        this.channelType = channelType;
        this.mqType = mqType;
        this.consumeMode = consumeMode;
        this.destinationName = destinationName;
        this.destinationType = destinationType;
        this.routingKey = routingKey;
        this.tag = tag;
        this.pushStrategy = pushStrategy;
        this.taskId = taskId;
    }

    /**
     * 转换为推送任务对象
     *
     * @return 推送任务对象
     */
    public NotificationPushTasks toPushTask() {
        NotificationPushTasks pushTask = new NotificationPushTasks();
        pushTask.setNotificationId(this.notificationId);
        pushTask.setChannelType(this.channelType);
        pushTask.setMqType(this.mqType);
        pushTask.setConsumeMode(this.consumeMode);
        pushTask.setDestinationName(this.destinationName);
        pushTask.setDestinationType(this.destinationType);
        pushTask.setRoutingKey(this.routingKey);
        pushTask.setTag(this.tag);
        pushTask.setPushStrategy(this.pushStrategy);
        return pushTask;
    }

}